<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="全局序号" prop="seqno">
      <el-input v-model="dataForm.seqno" placeholder="全局序号"></el-input>
    </el-form-item>
    <el-form-item label="多条记录,递增" prop="id">
      <el-input v-model="dataForm.id" placeholder="多条记录,递增"></el-input>
    </el-form-item>
    <el-form-item label="查询时间" prop="qrytime">
      <el-input v-model="dataForm.qrytime" placeholder="查询时间"></el-input>
    </el-form-item>
    <el-form-item label="区域" prop="region">
      <el-input v-model="dataForm.region" placeholder="区域"></el-input>
    </el-form-item>
    <el-form-item label="查询开始日期" prop="begindate">
      <el-input v-model="dataForm.begindate" placeholder="查询开始日期"></el-input>
    </el-form-item>
    <el-form-item label="查询结束日期" prop="enddate">
      <el-input v-model="dataForm.enddate" placeholder="查询结束日期"></el-input>
    </el-form-item>
    <el-form-item label="不动产状态:1-再次抵押;2-被查封;3-居住权" prop="status">
      <el-input v-model="dataForm.status" placeholder="不动产状态:1-再次抵押;2-被查封;3-居住权"></el-input>
    </el-form-item>
    <el-form-item label="抵押权人银行机构编号" prop="obankid">
      <el-input v-model="dataForm.obankid" placeholder="抵押权人银行机构编号"></el-input>
    </el-form-item>
    <el-form-item label="业务件号" prop="serviceno">
      <el-input v-model="dataForm.serviceno" placeholder="业务件号"></el-input>
    </el-form-item>
    <el-form-item label="不动产登记证明号" prop="realtyno">
      <el-input v-model="dataForm.realtyno" placeholder="不动产登记证明号"></el-input>
    </el-form-item>
    <el-form-item label="坐落" prop="addr">
      <el-input v-model="dataForm.addr" placeholder="坐落"></el-input>
    </el-form-item>
    <el-form-item label="抵押权人名称" prop="pledgeename">
      <el-input v-model="dataForm.pledgeename" placeholder="抵押权人名称"></el-input>
    </el-form-item>
    <el-form-item label="抵押人名称" prop="pledgername">
      <el-input v-model="dataForm.pledgername" placeholder="抵押人名称"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          serialno: 0,
          seqno: '',
          id: '',
          qrytime: '',
          region: '',
          begindate: '',
          enddate: '',
          status: '',
          obankid: '',
          serviceno: '',
          realtyno: '',
          addr: '',
          pledgeename: '',
          pledgername: '',
          remark: ''
        },
        dataRule: {
          seqno: [
            { required: true, message: '全局序号不能为空', trigger: 'blur' }
          ],
          id: [
            { required: true, message: '多条记录,递增不能为空', trigger: 'blur' }
          ],
          qrytime: [
            { required: true, message: '查询时间不能为空', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '区域不能为空', trigger: 'blur' }
          ],
          begindate: [
            { required: true, message: '查询开始日期不能为空', trigger: 'blur' }
          ],
          enddate: [
            { required: true, message: '查询结束日期不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '不动产状态:1-再次抵押;2-被查封;3-居住权不能为空', trigger: 'blur' }
          ],
          obankid: [
            { required: true, message: '抵押权人银行机构编号不能为空', trigger: 'blur' }
          ],
          serviceno: [
            { required: true, message: '业务件号不能为空', trigger: 'blur' }
          ],
          realtyno: [
            { required: true, message: '不动产登记证明号不能为空', trigger: 'blur' }
          ],
          addr: [
            { required: true, message: '坐落不能为空', trigger: 'blur' }
          ],
          pledgeename: [
            { required: true, message: '抵押权人名称不能为空', trigger: 'blur' }
          ],
          pledgername: [
            { required: true, message: '抵押人名称不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.serialno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.serialno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcrealtylist/info/${this.dataForm.serialno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.seqno = data.bdcRealtylist.seqno
                this.dataForm.id = data.bdcRealtylist.id
                this.dataForm.qrytime = data.bdcRealtylist.qrytime
                this.dataForm.region = data.bdcRealtylist.region
                this.dataForm.begindate = data.bdcRealtylist.begindate
                this.dataForm.enddate = data.bdcRealtylist.enddate
                this.dataForm.status = data.bdcRealtylist.status
                this.dataForm.obankid = data.bdcRealtylist.obankid
                this.dataForm.serviceno = data.bdcRealtylist.serviceno
                this.dataForm.realtyno = data.bdcRealtylist.realtyno
                this.dataForm.addr = data.bdcRealtylist.addr
                this.dataForm.pledgeename = data.bdcRealtylist.pledgeename
                this.dataForm.pledgername = data.bdcRealtylist.pledgername
                this.dataForm.remark = data.bdcRealtylist.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcrealtylist/${!this.dataForm.serialno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'serialno': this.dataForm.serialno || undefined,
                'seqno': this.dataForm.seqno,
                'id': this.dataForm.id,
                'qrytime': this.dataForm.qrytime,
                'region': this.dataForm.region,
                'begindate': this.dataForm.begindate,
                'enddate': this.dataForm.enddate,
                'status': this.dataForm.status,
                'obankid': this.dataForm.obankid,
                'serviceno': this.dataForm.serviceno,
                'realtyno': this.dataForm.realtyno,
                'addr': this.dataForm.addr,
                'pledgeename': this.dataForm.pledgeename,
                'pledgername': this.dataForm.pledgername,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
